<?php
/**
 * hlpValidateルールセット uTimeStamp型チェック
 * 入力値によって処理が異なる。
 */
include_once (dirname(__FILE__).'/default.php');

class Validate_check_uTimeStamp extends Validate_Rules_Default {

	function call () {
		// 入力・未入力・必須チェック
		if (!isset($this->SrcData[$this->Key])) {
			if (0 === strcasecmp($this->Rule['necessary'],'yes')) {
				$this->ErrMsg[] = $this->Rule['string'].'が入力されていません。';
				return false;
			} else {
				return true;
			}
		}
		
		if (is_array($this->SrcData[$this->Key])) {
			// 配列の時は各要素からmktimeを実行する
			$year   = isset ($this->SrcData[$this->Key]['year'])?((int)$this->SrcData[$this->Key]['year']):(0);
			$month  = isset ($this->SrcData[$this->Key]['month'])?((int)$this->SrcData[$this->Key]['month']):(0);
			$day    = isset ($this->SrcData[$this->Key]['day'])?((int)$this->SrcData[$this->Key]['day']):(0);
			$hour   = isset ($this->SrcData[$this->Key]['hour'])?((int)$this->SrcData[$this->Key]['hour']):(0);
			$minute = isset ($this->SrcData[$this->Key]['minute'])?((int)$this->SrcData[$this->Key]['minute']):(0);
			$second = isset ($this->SrcData[$this->Key]['second'])?((int)$this->SrcData[$this->Key]['second']):(0);
			$this->DstData[$this->Key] = mktime($hour, $minute, $second, $month, $day, $year);
		} elseif (is_string($this->SrcData[$this->Key])) {
			// 文字列の時はstrtotimeを実行する
			$this->DstData[$this->Key] = strtotime($this->SrcData[$this->Key]);
		} else {
			// それ以外の時はint型にキャストする
			$this->DstData[$this->Key] = (int) $this->SrcData[$this->Key];
		}
		return true;
	}
	
}
?>